package com.un.ebs.core.config;

import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.*;
import org.springframework.stereotype.Component;

import java.util.Properties;

/**
 * @author liubo
 * @email liubocs@163.com
 * @date 2020/5/4 18:24
 */
@Component
@Intercepts({@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class})})
public class MyBatisInterceptor implements Interceptor {
    @Override
    public Object intercept(Invocation invocation) throws Throwable {
//        System.out.println(invocation.getArgs()[0]);
//        MappedStatement mappedStatement = (MappedStatement)invocation.getArgs()[0];
//        Object parameter = invocation.getArgs()[1];
//        BoundSql sql = mappedStatement.getSqlSource().getBoundSql(parameter);
//        System.out.println(sql.getSql());
//        System.out.println(mappedStatement.getParameterMap().getType().getTypeName());
//        System.out.println();
//        Object ret = invocation.proceed();
//        System.out.println(ret);
//        return ret;
        return invocation.proceed();
    }

    @Override
    public Object plugin(Object target) {
        return Plugin.wrap(target, this);
    }

    @Override
    public void setProperties(Properties properties) {

    }
}

